part of '../repository.dart';

const _kTransactionUserRevocationSourceValue = 'user';
const _kTransactionDeveloperRevocationSourceValue = 'developer';
const _kTransactionGoogleRevocationSourceValue = 'google';

class _TransactionRevocationSourceDto extends Equatable {
  const _TransactionRevocationSourceDto._internal({
    required this.sourceString,
  });

  final String sourceString;

  @override
  List<Object?> get props {
    return [
      sourceString,
    ];
  }

  factory _TransactionRevocationSourceDto.fromString(String s) {
    return _TransactionRevocationSourceDto._internal(
      sourceString: s,
    );
  }

  factory _TransactionRevocationSourceDto.fromEntity(GooglePlayTransactionRevocationSource source) {
    late final String sourceString;

    if (source == GooglePlayTransactionRevocationSource.user) {
      sourceString = _kTransactionUserRevocationSourceValue;
    } else if (source == GooglePlayTransactionRevocationSource.developer) {
      sourceString = _kTransactionDeveloperRevocationSourceValue;
    } else if (source == GooglePlayTransactionRevocationSource.google) {
      sourceString = _kTransactionGoogleRevocationSourceValue;
    }

    return _TransactionRevocationSourceDto._internal(
      sourceString: sourceString,
    );
  }

  @override
  String toString() {
    return sourceString;
  }

  GooglePlayTransactionRevocationSource toEntity() {
    if (sourceString == _kTransactionUserRevocationSourceValue) {
      return GooglePlayTransactionRevocationSource.user;
    } else if (sourceString == _kTransactionDeveloperRevocationSourceValue) {
      return GooglePlayTransactionRevocationSource.developer;
    } else if (sourceString == _kTransactionGoogleRevocationSourceValue) {
      return GooglePlayTransactionRevocationSource.google;
    }

    throw UnimplementedError();
  }
}
